package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.login.TsLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.model.user.UserListenProcess;
import com.atguigu.tingshu.user.service.UserListenProcessService;
import com.atguigu.tingshu.vo.user.UserListenProcessVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Map;

@Tag(name = "用户声音播放进度管理接口")
@RestController
@RequestMapping("api/user/userListenProcess")
@SuppressWarnings({"all"})
public class UserListenProcessApiController {

	@Autowired
	private UserListenProcessService userListenProcessService;
//	http://127.0.0.1/api/user/userListenProcess/getTrackBreakSecond/14090
	@TsLogin
	@Operation(summary = "查找当前声音播放的进度")
	@GetMapping("/getTrackBreakSecond/{trackId}")
	public Result<BigDecimal> getTrackBreakSecond(@PathVariable Long trackId){
//	  	从线程中获取用户id
		Long userId = AuthContextHolder.getUserId();
//		调用service层的方法
		BigDecimal bigDecimal = userListenProcessService.getTrackBreakSecond(userId,trackId);
		return Result.ok(bigDecimal);
	}

//	@PostMapping("/updateListenProcess")
	@TsLogin
	@Operation(summary = "保存最新的播放进度")
	@PostMapping("/updateListenProcess")
	public Result updateListenProcess(@RequestBody UserListenProcessVo userListenProcessVo){
//		从线程中获取用户id
		Long userId = AuthContextHolder.getUserId();
//		调用service层方法去保存用户播放进度
		userListenProcessService.updateListenProcess(userId,userListenProcessVo);
		return Result.ok();
	}
//	http://127.0.0.1/api/user/userListenProcess/getLatelyTrack
	@TsLogin
	@Operation(summary = "获取用户最近播放的音乐")
	@GetMapping("/getLatelyTrack")
	public Result getLatelyTrack(){
//		从线程中获取用户id
		Long userId = AuthContextHolder.getUserId();
//		调用service层的方法
		Map<String,Object> map =  userListenProcessService.getLatelyTrack(userId);
		return Result.ok(map);
	}
}

